package lab3;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MexWindow extends JFrame {
	/**
	 * Data members
	 * serialVersionUID - declaring and assigning a value prevents warning messages.
	 * origTitle - title for the window
	 * jContentPane
	 * jPanel
	 * jButton
	 */
	private static final long serialVersionUID = 1L;
	private String origTitle = new String("Mex3 window");
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JButton jButton = null;
	private int panelwidth = 300;
	private int panelheight = 180;


	/**
	 * This is the default constructor
	 */
	public MexWindow() {
		super();
		initialize();
	}

	/**
	 * Initialize the MexWindow object
	 * 
	 * @return void
	 */
	private void initialize() {
		/**
		 * Initialize the jButton
		 */
		if (jButton == null) {
			jButton = new JButton();
			jButton.setText("Start");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				//	loop();
				}
			});
		}

		/**
		 * Initialize the jPanel
		 */
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(new GridBagLayout());
			jPanel.setMinimumSize(new Dimension(panelwidth, panelheight));
			jPanel.setPreferredSize(new Dimension(panelwidth, panelheight));
			jPanel.setBackground(Color.black);
		}
		/**
		 * Initialize the jContentPane
		 */
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new FlowLayout());
			jContentPane.add(jButton, null);
			jContentPane.add(jPanel, null);
		}
		setContentPane( jContentPane );
		setTitle(origTitle);
		setPreferredSize(new Dimension(400, 300));
		setBounds(new Rectangle(200, 100, 400, 300));
		setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	}

	/*
	 * Paint method for the window
	 * 
	 * @see java.awt.Container#paint(java.awt.Graphics)
	 */
	public void paint(java.awt.Graphics g) {
		super.paint(g);

		/*
		 * Get the window size and change the size of the panel if the user has
		 * resized the window.
		 */
		System.out.println("paint called. Frame width = " + getWidth() + " and height = " + getHeight() );
		jPanel.setSize((int)(0.8*getWidth()), (int)(0.8*getHeight()) );
		panelwidth = jPanel.getWidth();
		panelheight = jPanel.getHeight();
		System.out.println("              Panel width = "  + panelwidth + " and height = " + panelheight );

	}
	
	private void loop(){
		while (true)
			;
	}
}